package com.ukee.birthday.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ukee.birthday.common.utils.PageUtils;
import com.ukee.birthday.common.utils.Query;
import com.ukee.birthday.modules.dao.MealDao;
import com.ukee.birthday.modules.entity.MealEntity;
import com.ukee.birthday.modules.service.MealService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("mealService")
public class MealServiceImpl extends ServiceImpl<MealDao, MealEntity> implements MealService {

    @Resource
    private MealDao mealDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String username = (String)params.get("username");
        String state = (String)params.get("state");
        String startTime = (String)params.get("startTime");
        String endTime = (String)params.get("endTime");

        IPage<MealEntity> page = null;
        page = mealDao.queryPage(new Query<MealEntity>().getPage(params),username,state,startTime,endTime);
        return new PageUtils(page);
    }

    @Override
    public List<MealEntity> getList(Integer uid) {
        return mealDao.getList(uid);
    }

    @Override
    public List<MealEntity> getYearList(Integer uid) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        return mealDao.getYearList(uid,year);
    }

    @Override
    public List<MealEntity> getMonthOrder() {
        Calendar cal = Calendar.getInstance();
//        int year = cal.get(Calendar.YEAR);
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String datef = sdf.format(date);
        System.out.println("查询月份："+datef);
        return mealDao.getMonthOrder(datef);
    }

    @Override
    public List<MealEntity> getDayOrder(String dateStr) {
//        Calendar cal = Calendar.getInstance();
//        int day = cal.get(Calendar.DAY_OF_MONTH);
//        System.out.println("day====="+day);

//        Date date = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        String datef = sdf.format(date);
//        System.out.println("格式化后的日期：" + datef);

//        return mealDao.getDayList(datef);
        System.out.println("查询日期：" + dateStr);
        return mealDao.getDayList(dateStr);
    }

    @Override
    public List<MealEntity> getVerifyList(Integer vId) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        return mealDao.getVerifyList(vId,year);
    }

    @Override
    public PageUtils queryVerifyPage(Map<String, Object> params) {
        String vId = (String)params.get("vId");
        IPage<MealEntity> page = null;
        page = mealDao.queryVerifyPage(new Query<MealEntity>().getPage(params),vId,"2");
        return new PageUtils(page);
    }


}
